import java.io.*;
import java.util.*;

public class Main {
	String input;
	StringTokenizer st;
	BufferedReader br;
	StringBuilder sb;
	
	int m,
		n,
		x,
		y,
		diff,
		minDistance;
	int[][] subImg,
			img,
			diffTable;
	
	public Main() {
		br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder();
	}
	
	public static void main(String[] args) throws IOException {
		Main main = new Main();
		main.beginProcess();
	}

	void beginProcess() throws IOException {
		int i,
			j,
			curDiff,
			curDistance;
		while((input = br.readLine()) != null) {
			st = new StringTokenizer(input);
			m = Integer.parseInt(st.nextToken());
			subImg = new int[m][m];
			for(i = 0; i < m; i++) {
				input = br.readLine();
				st = new StringTokenizer(input);
				for(j = 0; j < m; j++)
					subImg[i][j] = Integer.parseInt(st.nextToken());
			}
			
			input = br.readLine();
			st = new StringTokenizer(input);
			n = Integer.parseInt(st.nextToken());
			img = new int[n][n];
			for(i = 0; i < n; i++) {
				input = br.readLine();
				st = new StringTokenizer(input);
				for(j = 0; j < n; j++)
					img[i][j] = Integer.parseInt(st.nextToken());
			}
			
			diff = Integer.MAX_VALUE;
			minDistance = Integer.MAX_VALUE;
			x = 1;
			y = 1;
			getDiffTable();
			for(i = 0; i <= n - m; i++)
				for(j = 0; j <= n - m; j++) {
					curDiff = template_matching(i, j);
					if(curDiff <= diff) {
						curDistance = getDistance(i, j);
						if(curDiff == diff) {
							if(curDistance < minDistance) {
								minDistance = curDistance;
								x = i + 1;
								y = j + 1;
							}
						} else {
							diff = curDiff;
							minDistance = curDistance;
							x = i + 1;
							y = j + 1;
						}
					}
				}
			sb.append(x + " " + y + "\n");
		}
		System.out.print(sb);
	}
	
	void getDiffTable() {
		int i,
		    j,
		    begin,
		    end,
		    tailIdx,
		    diff;
		
		tailIdx = m - 1;
		diff = 1;
		diffTable = new int[m][m];
		for(i = 0 ; i < m / 2; i++) {
			for(j = 0 ; j < m; j++) {
				diffTable[i][j] = diff;
				diffTable[tailIdx - i][j] = diff;
			}
			diff++;
		}
		if(!(m % 2 == 0)) diffTable[m / 2][m / 2] = diff;
		
		diff = 1;
		begin = 1;
		end = m - 1;
		for(j = 0; j < m / 2; j++) {
			for(i = begin; i < end; i++) {
				diffTable[i][j] = diff;
				diffTable[i][tailIdx - j] = diff;
			}
			diff++;
			begin++;
			end--;
		}
	}
	
	int template_matching(int ni, int nj) {
		int i,
			j,
			initnj,
			curDiff;
		
		initnj = nj;
		curDiff = 0;
		for(i = 0; i < m; i++) {
			nj = initnj;
			for(j = 0; j < m; j++) {
				if(!(subImg[i][j] == img[ni][nj])) curDiff += diffTable[i][j];
				nj++;
			}
			ni++;
		}
		
		return curDiff;
	}
	
	int getDistance(int x, int y) {
		return x * x + y * y;
	}
	
}